<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
</head>

<body>
    <script>
        let numbers = [{
            a: 1,
        }, {
            a: 2,
        }, {
            a: 5,
        }, ]; //请使用map方法将numbers数据变为[3,6,9,12,15]

        numbers.splice(
            2,
            0, {
                a: 3,
            }, {
                a: 4,
            }
        );
        let res = numbers.map((i) => i.a * 3);
        console.log(res);

        console.log(
            [{
                a: 1,
            }, {
                a: 2,
            }, ].join(",")
        );

        // let arr = [1, 2, 3, 4, 5];
        // console.log(arr.reduce((total, next) => total + next));

        // 去重
        let arr = [1, 2, 3, 4, 3, 2, 4, 5, 3, 2];
        let newArr = [];
        for (let i = 0; i < arr.length; i++) {
            if (newArr.indexOf(arr[i]) == -1) {
                newArr.push(arr[i]);
            }
        }
        console.log(newArr);

        // 排序 sort 排序

        // 冒泡 排序
        let arr2 = [203, 123, 34, 56, 890, 2, 45, 345];

        for (let i = 0; i < arr2.length; i++) {
            for (let j = 0; j < arr2.length - i - 1; j++) {
                if (arr2[j] > arr2[j + 1]) {
                    [arr2[j], arr2[j + 1]] = [arr2[j + 1], arr2[j]];
                    //让a和b交换位置
                }
            }
        }
        console.log(arr2);

        // 用解构赋值 交换ab的位置
        let a = 10,
            b = 20;

        [a, b] = [b, a];
    </script>
</body>

</html>